package com.example.itshome.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.itshome.R;
import com.example.itshome.impl.ViewOutlineProviderImpl;
import com.example.itshome.entity.ActivityEntity;

import java.util.List;

public class SignInActivityRecycleViewAdapter extends RecyclerView.Adapter<SignInActivityRecycleViewAdapter.SignInActivityViewHolder> {

    private final List<ActivityEntity> mData;
    private final Context context;

    public SignInActivityRecycleViewAdapter(Context context,List<ActivityEntity> list){
        this.context=context;
        mData=list;
    }

    @NonNull
    @Override
    public SignInActivityViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(context, R.layout.recycle_signed_in_activity_item,null);
        view.setOutlineProvider(new ViewOutlineProviderImpl(20));
        view.setClipToOutline(true);
        SignInActivityViewHolder holder=new SignInActivityViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull SignInActivityViewHolder holder, int position) {
        ActivityEntity entity=mData.get(position);
        holder.activityNameTextView.setText(entity.getTitle());
        Log.i("r",entity.getLocate());
        holder.locateTextView.setText(entity.getLocate());

        Glide.with(context).load(entity.getPictureSrc()).placeholder(R.drawable.sample_picture).into(holder.imageView);
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class SignInActivityViewHolder extends RecyclerView.ViewHolder{

        ImageView imageView;
        TextView activityNameTextView;
        TextView locateTextView;
        public SignInActivityViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.imv_recycle_signed_in_activity_image);
            activityNameTextView=itemView.findViewById(R.id.txv_recycle_signed_in_activity_name);
            locateTextView=itemView.findViewById(R.id.txv_recycle_signed_in_activity_locate);

            imageView.setOutlineProvider(new ViewOutlineProviderImpl(20));
            imageView.setClipToOutline(true);
        }
    }
}
